﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace SHomeWorkshop.LunarPresentation.Converts
{
    public class ExpanderBtnForegroundConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null || values.Length != 2) return Brushes.White;

            Brush editDefBackground = values[0] as Brush;
            Brush expanderBackground = values[1] as Brush;

            Expressions.Expander expander = parameter as Expressions.Expander;
            if (expander != null)
            {
                if (expanderBackground == Brushes.Transparent)
                {
                    if (editDefBackground == Brushes.Transparent)//如果编辑器底色为透明
                    {
                        return Brushes.White;//编辑器底色为透明时，当白色看待——因为底图主要是白色的。
                    }

                    return editDefBackground;
                }
                else
                {
                    return expanderBackground;//注意，这里改透明色是没有用的——因为TextBlock本身的底色会挡住Expander的背景色。
                }
            }

            return editDefBackground;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
